// 导入 express 模块
const express = require("express");
const cookieParser = require("cookie-parser");

// 创建 web 对象
const app = express();
app.use(cookieParser());

// 创建路由规则
app.get("/set-cookie", (req, res) => {
  res.cookie("name", "pipi", { maxAge: 60 * 1000 });
  res.send("Homepage");
});

// 删除 cookie
app.get("/remove-cookie", (req, res) => {
  res.clearCookie("name");
  res.send("删除 cookie 成功……");
});

// 获取 cookie
app.get("/get-cookie", (req, res) => {
  console.log(req.cookies);
  res.send("获取 cookie 成功……");
});

// 监听端口，启动服务
app.listen(3000, () => {
  console.log("cookie的使用：服务已经启动……");
});
